package cn.tt.tuantuanerp.tuantuanerp.warehouse.controller;

import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.dto.ProductCheckDTO;
import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.dto.WarehouseCheckDTO;
import cn.tt.tuantuanerp.tuantuanerp.comment.pojo.vo.ProductCheckVO;
import cn.tt.tuantuanerp.tuantuanerp.comment.security.LoginPrincipal;
import cn.tt.tuantuanerp.tuantuanerp.comment.web.JsonResult;
import cn.tt.tuantuanerp.tuantuanerp.warehouse.service.IProductService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "9.商品盘点模块")
@RestController
@RequestMapping("/productCheck")
@Slf4j
public class ProductCheckController {
    @Autowired
    IProductService productService;

    @GetMapping("/{checkWarehouseId:[0-9]+}")
    @ApiOperationSupport(order = 420)
    @ApiOperation("根据ID查询相应的商品列表")
    public JsonResult<List<ProductCheckVO>> list(@PathVariable Long checkWarehouseId){
        log.debug("开始处理展示盘点商品列表");
        return JsonResult.ok(productService.list(checkWarehouseId));
    }

    @PostMapping("/addproductcheck")
    @ApiOperationSupport(order = 100)
    @ApiOperation("新增盘点批次,批量增加盘点商品")
    public JsonResult addNew(@RequestBody WarehouseCheckDTO warehouseCheckDTO,
                             @ApiIgnore @AuthenticationPrincipal LoginPrincipal loginPrincipal){
        log.debug("Controller:开始处理添加盘点批次和商品列表的业务");
        log.debug("Controller:开始处理添加盘点批次和商品列表的业务{}",warehouseCheckDTO);
        productService.addNew(warehouseCheckDTO,loginPrincipal);
        return JsonResult.ok("添加成功");
    }
}
